      <section id="content">
        <div class="content-left">
          <h2>Zprávy</h2>
          <ul class="menu">
            <li class="active"><a href="<?php echo url::base() ?>messages" title="Poslat novou zprávu">Napsat zprávu</a></li>
            <li><a href="<?php echo url::base(); ?>messages/view" title="Přijaté zprávy">Přijaté</a></li>
            <li><a href="<?php echo url::base(); ?>messages/sent" title="Odeslané zprávy">Odeslané</a></li>
            <li><a href="<?php echo url::base(); ?>messages/cache" title="Rozepsané zprávy">Rozepsané<span id="plus-menu-cache" class="plus-menu-right hide">+1</span></a></li>
          </ul>
          <div class="content-left-bottom menu-left-bottom"></div>
        </div>
        <div class="content-right">
          <header>
            <h2>Napsat zprávu</h2>
          </header>
          <section>
          <?php
          if (!isset($dataPost) && !isset($messages_cache)) { $dataPost = array('to_username' => '', 'text' => ''); }          
          ?>
          <form id="right" action="<?php echo url::base() ?>messages" method="post">
            <fieldset>
              <ul>
                <li>
                  <label for="to_username">Příjemce:</label>
                  <input id="tousername" type="text" name="to_username" value="<?php echo $dataPost['to_username'] ?>" class="text" />
                </li>
                <li>
                  <label for="text">Text:</label>
                  <textarea cols="10" rows="10" id="text" name="text" class="text" ><?php echo $dataPost['text'] ?></textarea>
                </li>
                <li>
                  <input class="float-right" type="submit" name="form-submit" value="Odeslat zprávu"  />
                  <span id="save-to-cache" class="float-right saving">Ukládám</span>
                </li>
              </ul>
              <input type="hidden" name="pattern" value="<?php echo Text::random() ?>"  />
            </fieldset>
          </form>
            <script type="text/javascript">
              $(document).ready(function(){
                autosave();

                var cache = {}, lastXhr;
		$( "#tousername" ).autocomplete({
                  minLength: 1,
                  source: function( request, response ) {                    
                    var term = request.term;
                    if ( term in cache ) {
                      response( cache[ term ] );
                      return;
                    }

                    lastXhr = $.getJSON( "<?php echo url::base(); ?>messages/tousername", request, function( data, status, xhr ) {
                      cache[ term ] = data;
                      if ( xhr === lastXhr ) {
                        response( data );
                      }
                    });
                  }
		});
              });

              function autosave() {
                var t = setTimeout("autosave()", 10000);
                var text = $("textarea#text").val();

                if (text.length > 10) {
                  $("#save-to-cache").show();
                  var formData = $("form#right").serializeArray();
                  $.ajax({
                    type: "POST",
                    url: "<?php echo url::base() ?>messages/cache",
                    data: $("form#right").serializeArray(),
                    cache: false,
                    success: function(message) {
                      $("#plus-menu-cache").fadeIn('slow');
                      $("#save-to-cache").delay(1500).fadeOut();
                    }
                  });
                }
              }
            </script>
          </section>
          <div class="content-right-bottom"></div>
        </div>                          	   	
      </section>